import {_decorator, Animation, AnimationClip, Component, SpriteFrame} from 'cc';
import {DIRECTION_ENUM, DIRECTION_ORDER_ENUM, FSM_TYPE_ENUM, PARAMS_NAME_ENUM} from "../../Enums";
import State from "../../Base/State";
import {getInitParamNumber, getInitParamTrigger, StateMachine} from "../../Base/StateMachine";
import {SubStateMachine} from "../../Base/SubStateMachine";

const { ccclass, property } = _decorator;

export class FourDirectionSubPlayerStateMachine extends SubStateMachine {

    constructor(fsm: StateMachine, stateStr: string, wrapMode: AnimationClip.WrapMode = AnimationClip.WrapMode.Normal) {
        super(fsm);

        const BASE_URL = `texture/player/${stateStr}/`;

        this.stateMachines.set(DIRECTION_ENUM.TOP, new State(fsm, `${BASE_URL}top`, wrapMode));
        this.stateMachines.set(DIRECTION_ENUM.BOTTOM, new State(fsm, `${BASE_URL}bottom`, wrapMode));
        this.stateMachines.set(DIRECTION_ENUM.LEFT, new State(fsm, `${BASE_URL}left`, wrapMode));
        this.stateMachines.set(DIRECTION_ENUM.RIGHT, new State(fsm, `${BASE_URL}right`, wrapMode));
    }

    run() {
        const value = this.fsm.getParam(PARAMS_NAME_ENUM.DIRECTION);
        this.currentState = this.stateMachines.get(DIRECTION_ORDER_ENUM[value as number]);
    }
}


export class IdleSubPlayerStateMachine extends FourDirectionSubPlayerStateMachine {
    constructor(fsm: StateMachine) {
        super(fsm, 'idle', AnimationClip.WrapMode.Loop);
    }
}
export class TurnLeftSubPlayerStateMachine extends FourDirectionSubPlayerStateMachine {
    constructor(fsm: StateMachine) {
        super(fsm, 'turnleft');
    }
}
export class TurnRightSubPlayerStateMachine extends FourDirectionSubPlayerStateMachine {
    constructor(fsm: StateMachine) {
        super(fsm, 'turnright');
    }
}


